package com.justgame.project.module;

import static com.justgame.project.generator.schema.Field.*;
import static com.justgame.project.generator.schema.Join.leftJoin;
import static com.justgame.project.generator.schema.Service.AddBy.Param.column;
import static com.justgame.project.generator.schema.Service.AddBy.Param.init;


import com.justgame.project.generator.enums.Rule;
import com.justgame.project.generator.schema.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.io.Serializable;

@Configuration
public class JustModule implements IModule, Serializable {
    @Override
    public String getModule() {
        return "just";
    }

    @Bean
    public Entity JustGameAttention(){
        return Entity.baseEntityBuilder(getModule(),"JustGameAttention","游戏信息关注表")
                .fields(
                        key("gameInfoId","游戏信息ID"),
                        type("target","来源")
                )
                .enums(
                        Enumerate.builder("target")
                                .item("HOME","首页")
                                .item("GAME_DETAIL","游戏详情页")
                )
                .service(
                        Service.builder()
                                .findBy(Service.FindBy.builder().is("gameInfoId").is("target").build())
                                .listBy(Service.ListBy.builder().is("gameInfoId").build())
                                .updateBy(Service.UpdateBy.builder().param("target").build())
                                .addBy(Service.AddBy.builder()
                                        .params(
                                                column("gameInfoId").rule(Rule.notNull()),
                                                column("target").rule(Rule.notNull())
                                        )
                                        .build())
                                .build()
                )
                .joinTables(
                        leftJoin("gameInfoId","JustGameInfo","id")
                )
                .build();
    }

    @Bean
    public Entity JustGameInfo(){
        return Entity.baseEntityBuilder(getModule(),"JustGameInfo","游戏信息表")
                .fields(
                        string("cnName","中文名"),
                        string("enName","英文名"),
                        string("images","封面图片"),
                        string("website","官网"),
                        text("desc","描述"),
                        key("companyId","游戏开发公司id"),
                        decimal("amount","价格"),
                        type("type","游戏类型")
                )
                .joinTables(
                        leftJoin("companyId","JustGameCompany","id")
                )
                .enums(
                        Enumerate.builder("type")
                                .item("COMMON","普通")
                                .item("VIP","会员")
                )
                .build();
    }

    @Bean
    public Entity JustGameCompany(){
        return Entity.baseEntityBuilder(getModule(),"JustGameCompany","游戏发行方信息")
                .fields(
                        string("name","发行商名称"),
                        url("imageUrl","发行商封面图"),
                        text("description","介绍描述")
                )
                .build();
    }

    @Bean
    public Entity JustGameAddition(){
        return Entity.baseEntityBuilder(getModule(),"JustGameAddition","游戏信息附加资源表")
                .fields(
                        key("gameInfoId","游戏信息"),
                        type("type","类型"),
                        url("url","附加资源链接")
                )
                .enums(
                        Enumerate.builder("type")
                                .item("IMAGE","图片")
                                .item("VIDEO","视频")
                )
                .joinTables(
                        leftJoin("gameInfoId","JustGameInfo","id")
                )
                .build();
    }

    @Bean
    public Entity JustGameCloud(){
        return Entity.baseEntityBuilder(getModule(),"JustGameCloud","游戏资源网盘映射表")
                .fields(
                        string("title","标题"),
                        url("path","云盘链接"),
                        string("secretKey","云盘密钥"),
                        key("gameInfoId","游戏信息")
                )
                .joinTables(
                        leftJoin("gameInfoId","JustGameInfo","id")
                )
                .build();
    }

    @Bean
    public Entity JustGameComment(){
        return Entity.baseEntityBuilder(getModule(),"JustGameComment","游戏评论")
                .fields(
                        key("parentId","上级评论"),
                        string("ancestors","评论关联族谱"),
                        key("gameInfoId","游戏信息"),
                        text("content","评论内容"),
                        type("type","类型"),
                        bool("isPixelate","是否匿名"),
                        bool("isRemove","是否被显性删除")
                )
                .joinTables(
                        leftJoin("parentComment","parentId","JustGameComment","id"),
                        leftJoin("gameInfoId","JustGameInfo","id")
                )
                .enums(
                        Enumerate.builder("type")
                                .item("LANDLORD","楼主")
                                .item("FOLLOW","回复")
                )
                .service(
                        Service.builder()
                                .addBy(
                                        Service.AddBy.builder()
                                                .name("addLandlordComment")
                                                .description("发表评论 - 楼主")
                                                .params(
                                                        column("gameInfoId"),
                                                        column("content"),
                                                        column("isPixelate").defaultValue("false"),
                                                        init("isRemove","false"),
                                                        init("type","LANDLORD")
                                                )
                                                .build()
                                )
                                .build()
                )
                .build();
    }

    @Bean
    public Entity JustViewGameLog(){
        return Entity.baseEntityBuilder(getModule(),"JustViewGameLog","游戏浏览记录表")
                .fields(
                        key("gameInfoId","游戏信息"),
                        key("userInfoId","用户信息"),
                        string("ip","ip地址")
                )
                .joinTables(
                        leftJoin("gameInfoId","JustGameInfo","id"),
                        leftJoin("userInfo","userInfoId","SysUserInfo","id")
                )
                .build();
    }

    @Bean
    public Entity JustGamePlatform(){
        return Entity.baseEntityBuilder(getModule(),"JustGamePlatform","游戏平台")
                .fields(
                        string("name","名称"),
                        string("platformVersion","平台版本"),
                        string("notice","其他须知"),
                        url("imageUrl","封面图"),
                        text("description","描述")
                )
                .build();
    }

    @Bean
    public Entity JustGameScore(){
        return Entity.baseEntityBuilder(getModule(),"JustGameScore","游戏评分表")
                .fields(
                        key("gameInfoId","游戏信息"),
                        decimal("score","分数")
                )
                .joinTables(
                        leftJoin("gameInfoId","JustGameInfo","id")
                )
                .build();
    }

    @Bean
    public Entity JustGameType(){
        return Entity.baseEntityBuilder(getModule(),"JustGameType","游戏类型表")
                .fields(
                        string("chineseName","中文名称"),
                        string("englishName","英文名称"),
                        string("logoType","iconfont对应的图标Type类型"),
                        text("description","描述"),
                        type("status","状态")
                )
                .enums(
                        Enumerate.builder("status")
                                .item("ENABLE","启用")
                                .item("DISABLE","禁用")
                )
                .build();
    }

    @Bean
    public Entity JustGameTypeMap(){
        return Entity.builder(getModule(),"JustGameTypeMap","游戏类型映射表")
                .fields(
                        key("typeId","游戏类型信息"),
                        key("gameInfoId","游戏信息")
                )
                .joinTables(
                        leftJoin("gameInfoId","JustGameInfo","id"),
                        leftJoin("typeId","JustGameType","id")
                )
                .build();
    }

    @Bean
    public Entity JustPlatformMap(){
        return Entity.builder(getModule(),"JustPlatformMap","游戏版本映射表")
                .fields(
                        key("gameInfoId","游戏信息"),
                        key("gamePlatformId","游戏平台")
                )
                .joinTables(
                        leftJoin("gameInfoId","JustGameInfo","id"),
                        leftJoin("gamePlatformId","JustGamePlatform","id")
                )
                .build();
    }
}
